package com.xpalive.exception;

import com.xpalive.commons.Constants.RespCode;
import lombok.Data;

/**
 * 自定义业务异常
 */
@Data
public class BizException extends RuntimeException {

    private final String message;

    private final RespCode code;

    public static BizException of(Throwable cause) {
        return new BizException(cause);
    }

    public static BizException of(RespCode code) {
        return new BizException(code.getCodeMessage(), code);
    }

    public static BizException of(RespCode code, Throwable cause) {
        return new BizException(code.getCodeMessage(), code, cause);
    }

    public static BizException of(String message) {
        return new BizException(message);
    }

    public static BizException of(String message, Throwable cause) {
        return new BizException(message, cause);
    }

    public BizException(Throwable cause) {
        super(cause);
        this.message = cause.getMessage();
        this.code = RespCode.E500;
    }

    public BizException(String message) {
        super(message);
        this.message = message;
        this.code = RespCode.E500;
    }

    public BizException(String message, Throwable cause) {
        super(message, cause);
        this.message = message;
        this.code = RespCode.E500;
    }

    public BizException(String message, RespCode code) {
        super(message);
        this.message = message;
        this.code = code;
    }

    public BizException(String message, RespCode code, Throwable cause) {
        super(message, cause);
        this.message = message;
        this.code = code;
    }
}
